package club.banyuan.hrms.servlet;

import club.banyuan.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "ForwardTargetServlet", urlPatterns = "/st4")
public class ForwardTargetServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        User user = (User) request.getAttribute("user");
        response.setHeader("User-Name", (user != null) ? user.getName() : "");
        if ((user != null) && (user.getAge() != null)) {
            response.setHeader("User-Age", user.getAge().toString());
        } else {
            response.setHeader("User-Age", "");
        }

        response.setContentType("text/html;charset=utf-8");
        response.getWriter().println("target");
//        String name = user.getName();
//        int age = user.getAge();

//        response.getWriter().println("name: " + name);
//        response.getWriter().println("age: " + age);

    }
}
